from xml.dom.minidom import parse

# nmap扫描结果的xml文件
domTree = parse(r"Y:\source_code\vue\st\jichust\day7\router-demo1\nmapScan.xml.xml")
rootNode = domTree.documentElement
hosts = rootNode.getElementsByTagName('host')
myPort = "80" # 需要指定的端口号
for h in hosts:
    state = h.getElementsByTagName('status')[0].getAttribute('state')
    isBre = False
    if state == "up":
        ports = h.getElementsByTagName('port')
        for port in ports:
            portSate = port.getElementsByTagName('state')[0].getAttribute('state')
            if portSate == 'open':
                portid = port.getAttribute('portid')
                if portid == myPort:
                    ip = h.getElementsByTagName('address')[0].getAttribute('addr')
                    print(ip)
                    isBre = True
                    break
        if isBre:
            continue
